package com.jy.adscm.operation.mscyb.service.impl;

import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.mscyb.bean.JqdbSettings;
import com.jy.adscm.operation.mscyb.bean.JqfzSetting;
import com.jy.adscm.operation.mscyb.mapper.mysql.JqdbSettingsMapper;
import com.jy.adscm.operation.mscyb.service.JqdbSettingsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.zltx.bean.JyDrawingType;
import com.jy.adscm.zltx.mapper.mysql.JyDrawingTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-06-17
 */
@Service
public class JqdbSettingsServiceImpl extends ServiceImpl<JqdbSettingsMapper, JqdbSettings> implements JqdbSettingsService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Autowired
    JyDrawingTypeMapper jyDrawingTypeMapper;
    @Override
    public JqdbSettings selectJqdbSettingsById(String id) {
        JqdbSettings jqdbSettings = super.selectById(id);
        if (AdscmBaseUtils.getInstance().isNotEmpty(jqdbSettings,null)){
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqdbSettings.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(jqdbSettings.getCreator());
                jqdbSettings.setCreatorName(jyUser.getName());
            }

        }
        return jqdbSettings;
    }

    @Override
    public List<JqdbSettings> selectAll() {
        List<JqdbSettings> jqdbSettings = super.selectList(null);
        for (JqdbSettings jqdbSetting : jqdbSettings) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqdbSetting.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(jqdbSetting.getCreator());
                jqdbSetting.setCreatorName(jyUser.getName());
            }
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqdbSetting.getType(),null)){
                JyDrawingType jyDrawingType = jyDrawingTypeMapper.selectById(jqdbSetting.getType());
                jqdbSetting.setTypeName(jyDrawingType.getType());
            }
        }
        return jqdbSettings;
    }
}
